package com.adv.ems.manager.impl;

import com.adv.ems.db.mapper.CircuitDiagramNodeEnergySubjectRelationMapper;
import com.adv.ems.db.entity.CircuitDiagramNodeEnergySubjectRelationDO;
import com.adv.ems.enums.SubjectTypeEnum;
import com.adv.ems.manager.CircuitDiagramNodeEnergySubjectRelationManager;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CircuitDiagramNodeEnergySubjectRelationManagerImpl extends BaseManagerImpl<CircuitDiagramNodeEnergySubjectRelationMapper, CircuitDiagramNodeEnergySubjectRelationDO> implements CircuitDiagramNodeEnergySubjectRelationManager {

    @Override
    public List<Long> getDiagramNodeIds(Collection<Long> subjectIds, SubjectTypeEnum type) {
        if (subjectIds.isEmpty()) {
            return new ArrayList<>();
        }
        return list()
                .stream()
                .filter(l -> subjectIds.contains(l.getSubjectId()))
                .filter(l -> type.name().equals(l.getType()))
                .map(CircuitDiagramNodeEnergySubjectRelationDO :: getDiagramNodeId)
                .collect(Collectors.toList());
    }

    @Override
    public void saveData(CircuitDiagramNodeEnergySubjectRelationDO relation) {
        save(relation);
    }

    @Override
    public void deleteById(Long id) {
        removeById(id);
    }
}
